using Admin2024.Application.Contracts.FileUpload;
using Admin2024.Domain.IDomainService;
using Admin2024.Domain.ObjValue;
using AutoMapper;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace Admin2024.Application.FileUpload;

public class AppFileUploadService : IAppFileUploadService
{
    private readonly IFileUploadService _fileUploadService;
    private readonly IMapper mapper;

    

    public AppFileUploadService(IFileUploadService fileUploadService,IMapper mapper){
        _fileUploadService = fileUploadService;
        this.mapper = mapper;
    }
    public async Task<DomainResult<FileContentResult>> GetFileByIdAsync(Guid appFileId)
    {
        var res =  await _fileUploadService.GetFileByIdAsync(appFileId);
        
        return res;
    }

    public async Task<DomainResult<FileUploadDto>> UploadFilesAsync(IFormFile file)
    {
        var res = await _fileUploadService.UploadFilesAsync(file);
        if (!res.IsSuccess)
        {
            return DomainResult<FileUploadDto>.Error(res.Message);
        }
        var fileUploadDto = mapper.Map<FileUploadDto>(res.Data);
        return DomainResult<FileUploadDto>.Success(fileUploadDto);
    }
}